Skip to content

Accept a beginless range of values for a bare Array type - #2992

Merged
ericproulx merged 1 commit into
masterfrom
fix/array-values-beginless-range
Sep 23, 2026
Merged

ericproulx merged 1 commit into
masterfrom
fix/array-values-beginless-range

Conversation

@ericproulx

Copy link
Copy Markdown
Contributor
params do
  requires :a, type: Array, values: ..5
end
# => RangeError: cannot get the first element of beginless range

Every release back to 2.1.3 raises this when the params are defined. For a bare type: Array, ValidationsSpec#guess_coerce_type guesses the member type that values: implies, so that the incompatible-values check can compare them. It asked values.first, which a beginless Range cannot answer. An endless Range (1..) was fine, and type: [Integer] never reaches the guess.

A Range now gives the class of its begin, or of its end when it has no begin. Specs cover a beginless and an endless range, plus a beginless range whose except_values: do not match the guessed type, which still raises IncompatibleOptionValues. Both beginless examples fail on master with the RangeError.

Found while covering the empty-list branch of the same line (#2983).

🤖 Generated with Claude Code

@ericproulx
ericproulx force-pushed the fix/array-values-beginless-range branch from efe42dd to e4aa1a0 Compare September 23, 2026 06:51
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Danger Report

No issues found.

View run

`requires :a, type: Array, values: ..5` raised `RangeError: cannot get
the first element of beginless range` while the params were defined:
`ValidationsSpec#guess_coerce_type` guessed the member type from
`values.first`, which a beginless Range cannot answer.

A Range now gives the class of its begin, or of its end when it has no
begin. The incompatible-values check that follows still runs against
that guess.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ericproulx
ericproulx force-pushed the fix/array-values-beginless-range branch from e4aa1a0 to 5555ff8 Compare September 23, 2026 15:05
@ericproulx
ericproulx merged commit afcbcee into master Sep 23, 2026
33 checks passed
@ericproulx
ericproulx deleted the fix/array-values-beginless-range branch September 23, 2026 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants